if (document.readyState !== 'loading') {
	eventHand();
} else {
	document.addEventListener('DOMContentLoaded', eventHand);
}
let xin_mydata;
//根据默认排序
$("#toDefault").click(function() {
	var table = document.getElementById("aaaa");
	var result = '';
	console.log("mu" + xin_mydata)
	for (var house of xin_mydata.tbHouses) {
		var myhtml = `
				 <dl>
				  <dt><a href="proinfo.html"><img src="${house.tbPicture.address}" width="286" height="188" /></a></dt>
				  <dd>
				   <h3><a href="proinfo.html">${house.houseType}，${house.introduce}
				   </a></h3>	
				   <div class="pro-wei">		
				    <img src="images/weizhi.png"" width="12" height="16" /> <strong class="red">${house.address}</strong>
				   </div>
				   <div class="pro-fang">${house.houseType} ${house.area}平 
				   `
		if (house.furniture == 2) {
			myhtml += `，家具齐全`
		}
		if (house.traffic == 2) {
			myhtml += `，交通方便`
		}
		if (house.elevator == 2) {
			myhtml += `，有电梯`
		}
		myhtml +=
			`
                </div> 
				   <div class="pra-fa">发布人：${house.tbAgent.name}  发布时间：${house.createTime}</div>
				  </dd>
				  <div class="price">¥ <strong>${house.price}</strong><span class="font12">元/月</span></div>
				  <div class="clears"></div>
				 </dl>
				 `;
		result += myhtml;
	}
	table.innerHTML = result;
})
//根据价格排序
$("#toNewHouse").click(function() {
	var table = document.getElementById("aaaa");
	var result = '';
	// console.log("mu" + xin_mydata)
	for (var house of xin_mydata.tbHouses_price) {
		var myhtml = `
				 <dl>
				  <dt><a href="proinfo.html"><img src="${house.tbPicture.address}" width="286" height="188" /></a></dt>
				  <dd>
				   <h3><a href="proinfo.html">${house.houseType}，${house.introduce}
				   </a></h3>	
				   <div class="pro-wei">		
				    <img src="images/weizhi.png"" width="12" height="16" /> <strong class="red">${house.address}</strong>
				   </div>
				   <div class="pro-fang">${house.houseType} ${house.area}平 
				   `
		if (house.furniture == 2) {
			myhtml += `，家具齐全`
		}
		if (house.traffic == 2) {
			myhtml += `，交通方便`
		}
		if (house.elevator == 2) {
			myhtml += `，有电梯`
		}
		myhtml +=
			`
                </div> 
				   <div class="pra-fa">发布人：${house.tbAgent.name}  发布时间：${house.createTime}</div>
				  </dd>
				  <div class="price">¥ <strong>${house.price}</strong><span class="font12">元/月</span></div>
				  <div class="clears"></div>
				 </dl>
				 `;
		result += myhtml;
	}
	table.innerHTML = result;
})
//根据时间排序
$("#toPrice").click(function() {
	var table = document.getElementById("aaaa");
	var result = '';
	// console.log("mu" + xin_mydata)
	for (var house of xin_mydata.tbHouses_time) {
		var myhtml = `
				 <dl>
				  <dt><a href="proinfo.html"><img src="${house.tbPicture.address}" width="286" height="188" /></a></dt>
				  <dd>
				   <h3><a href="proinfo.html">${house.houseType}，${house.introduce}
				   </a></h3>	
				   <div class="pro-wei">		
				    <img src="images/weizhi.png"" width="12" height="16" /> <strong class="red">${house.address}</strong>
				   </div>
				   <div class="pro-fang">${house.houseType} ${house.area}平 
				   `
		if (house.furniture == 2) {
			myhtml += `，家具齐全`
		}
		if (house.traffic == 2) {
			myhtml += `，交通方便`
		}
		if (house.elevator == 2) {
			myhtml += `，有电梯`
		}
		myhtml +=
			`
                </div> 
				   <div class="pra-fa">发布人：${house.tbAgent.name}  发布时间：${house.createTime}</div>
				  </dd>
				  <div class="price">¥ <strong>${house.price}</strong><span class="font12">元/月</span></div>
				  <div class="clears"></div>
				 </dl>
				 `;
		result += myhtml;
	}
	table.innerHTML = result;
})
async function eventHand() {
	var table = document.getElementById("aaaa");
	xin_mydata = await getData();
	var result = '';
	// console.log("mu" + xin_mydata)
	for (var house of xin_mydata.tbHouses) {
		var myhtml = `
				 <dl>
				  <dt><a href="proinfo.html"><img src="${house.tbPicture.address}" width="286" height="188" /></a></dt>
				  <dd>
				   <h3><a href="proinfo.html">${house.houseType}，${house.introduce}
				   </a></h3>	
				   <div class="pro-wei">		
				    <img src="images/weizhi.png"" width="12" height="16" /> <strong class="red">${house.address}</strong>
				   </div>
				   <div class="pro-fang">${house.houseType} ${house.area}平 
				   `
		if (house.furniture == 2) {
			myhtml += `，家具齐全`
		}
		if (house.traffic == 2) {
			myhtml += `，交通方便`
		}
		if (house.elevator == 2) {
			myhtml += `，有电梯`
		}
		myhtml +=
			`
                </div> 
				   <div class="pra-fa">发布人：${house.tbAgent.name}  发布时间：${house.createTime}</div>
				  </dd>
				  <div class="price">¥ <strong>${house.price}</strong><span class="font12">元/月</span></div>
				  <div class="clears"></div>
				 </dl>
				 `;
		result += myhtml;
	}
	table.innerHTML = result;
}
